/*===== EXPANDER MENU  =====*/
const showMenu = (toggleId, navbarId, bodyId)=>{
  const toggle = document.getElementById(toggleId),
      navbar = document.getElementById(navbarId),
      bodypadding = document.getElementById(bodyId)

  if(toggle && navbar){
    toggle.addEventListener('click', ()=>{
      navbar.classList.toggle('expander')

      bodypadding.classList.toggle('body-pd')
    })
  }
}
showMenu('nav-toggle','navbar','body-pd')

/*===== LINK ACTIVE  =====*/
const linkColor = document.querySelectorAll('.nav__link')
function colorLink(){
  linkColor.forEach(l=> l.classList.remove('active'))
  this.classList.add('active')
}
linkColor.forEach(l=> l.addEventListener('click', colorLink))


/*===== COLLAPSE MENU  =====*/
const linkCollapse = document.getElementsByClassName('collapse__link')
var i

for(i=0;i<linkCollapse.length;i++){
  linkCollapse[i].addEventListener('click', function(){
    const collapseMenu = this.nextElementSibling
    collapseMenu.classList.toggle('showCollapse')

    const rotate = collapseMenu.previousElementSibling
    rotate.classList.toggle('rotate')
  })
}

// // 获取所有侧边栏链接和内容区域
// const links = document.querySelectorAll('.nav__link');
// const contents = document.querySelectorAll('.content');
//
// // 为每个链接添加点击事件监听器
// links.forEach(link => {
//   link.addEventListener('click', function(event) {
//     event.preventDefault(); // 阻止默认的链接行为
//
//     // 移除所有链接和内容区域的'active'类
//     links.forEach(link => link.classList.remove('active'));
//     contents.forEach(content => content.classList.remove('active'));
//
//     // 为点击的链接和对应的内容区域添加'active'类
//     this.classList.add('active');
//     document.getElementById(this.getAttribute('href').slice(1)).classList.add('active');
//   });
// });


